﻿/*版权声明
 * 
 * 本 河北大学管理学院信息管理系网站 由
 * 河北大学 信管团队 开发
 * 如有任何疑问请联系开发人员
 * 
 * 项目开发者：朱胜贤、孙旭峰、水亚亚、张文元、项玥、吕芳、吴凡、谢静、李亚慧
 * 
 * 如有任何疑问请联系：河北大学信管团队
 * QQ：196396337
 * Email:zagelover@163.com
 * HomePage：http://sxgzs.com/
 * 
 * CopyRight (c) 河北大学信管团队 2010~2020
 */

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Admin_Notice_add : System.Web.UI.Page
{
    /// <summary>页面加载事件
    /// 	<remark>2010-10-21 河北大学信管团队-项玥 </remark>
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        //检查用户权限
        if (Session["Uid"] == null)
        {
            //无权限返回登录页
            Response.Redirect("AD_Login.aspx");
            return;
        }
        //情况消息框
        lblMessage.Text = "";
        if (!IsPostBack)
        {
            //提取URL传参
            string ID = Request.QueryString["ID"].ToString();
            if (ID == "")
            {//如果参数为空
                lblTitle.Text = "添加公告";
                btnCancel.Text = "清空";
            }
            else
            {//如果参数不为空
                lblTitle.Text = "编辑公告";
                Bind_Txt(ID);
            }
        }
    }

    /// <summary>绑定数据——文本框
    /// 	<remark>2010-10-23 河北大学信管团队-项玥 </remark>
    /// </summary>
    private void Bind_Txt(string ID)
    {
        //定义sql语句
        string sql = "select * from Notice_Info where notID=@notID";
        //定义参数
        SqlParameter[] para = { new SqlParameter("@notID", SqlDbType.Int) };
        //参数赋值
        para[0].Value = ID;
        //取得数据
        SqlDataReader DR = DataAccess.GetReader(sql, para);
        if (DR.HasRows)
        {//如果有数据
            while (DR.Read())
            {//显示数据
                ViewState["ID"] = ID;
                txtTitle.Text = DR["notTitle"].ToString();
                txtContent.Text = DR["notContent"].ToString();
                ckbIsShow.Checked = Convert.ToBoolean(DR["notIsShow"]);      
                ckbIsTop.Checked = Convert.ToBoolean(DR["notTop"]);
                lblID.Text = ID;
            }
        }
    }

    /// <summary>响应单击按钮事件——添加或者修改记录
    /// 	<remark>2010-10-23 河北大学信管团队-项玥  </remark>
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (lblTitle.Text.Trim() == "添加公告")
        {//如果是添加通知公告
            //定义sql语句
            string sql = "insert into Notice_Info(notTitle,notContent,notTime,notIsShow,notPublisher,notTop) values(@notTitle,@notContent,@notTime,@notIsShow,@notPublisher,@notTop)";
            //定义参数
            SqlParameter[] para = {
                    new SqlParameter("@notTitle", SqlDbType.NVarChar,50),
                    new SqlParameter("@notContent", SqlDbType.NText),
                    new SqlParameter("@notTime", SqlDbType.DateTime),
                    new SqlParameter("@notIsShow", SqlDbType.Bit),
                    new SqlParameter("@notPublisher", SqlDbType.NVarChar,10),
                    new SqlParameter("@notTop", SqlDbType.Bit)};
            //给参数赋值
            para[0].Value = txtTitle.Text.Trim();
            para[1].Value = txtContent.Text.Trim();
            para[2].Value = DateTime.Now.ToString();
            para[3].Value =ckbIsShow.Checked;
            para[4].Value = Session["Uid"];
            para[5].Value =ckbIsTop.Checked;
            if (DataAccess.GetCount(sql, para) > 0)
            {//如果添加成功
                //显示添加成功提示并转到管理页
                Response.Write("<script>alert('添加信息成功！');location.href='Notice_Manage.aspx';</script>");
            }
            else
            {//如果添加失败
                lblMessage.Text = "添加信息失败";
            }
        }
        else if (lblTitle.Text.Trim() == "编辑公告")
        {
            //定义sql语句
            string sql = "update Notice_Info set notTitle=@notTitle,notContent=@notContent, notTime=@notTime,notIsShow=@notIsShow,notPublisher=@notPublisher,notTop=@notTop where notID=@notID";
            //定义参数
            SqlParameter[] para = {
                    new SqlParameter("@notTitle", SqlDbType.NVarChar,50),
                    new SqlParameter("@notContent", SqlDbType.NText),
                    new SqlParameter("@notTime", SqlDbType.DateTime),
                    new SqlParameter("@notIsShow", SqlDbType.Bit),
                    new SqlParameter("@notPublisher", SqlDbType.NVarChar,10),
                    new SqlParameter("@notTop", SqlDbType.Bit),
                    new SqlParameter("@notID", SqlDbType.Int)};
            //给参数赋值
            para[0].Value = txtTitle.Text.Trim();
            para[1].Value = txtContent.Text.Trim();
            para[2].Value = DateTime.Now.ToString();
            para[3].Value = ckbIsShow.Checked;
            para[4].Value = Session["Uid"];
            para[5].Value = ckbIsTop.Checked;
            para[6].Value = lblID.Text.Trim();
            if (DataAccess.GetCount(sql, para) > 0)
            {//如果修改成功
                Response.Write("<script>alert('修改公告成功！');location.href='Notice_Manage.aspx';</script>");
            }
            else
            {//如果修改失败
                lblMessage.Text = "修改公告失败";
            }
        }
    }

    /// <summary>响应单击按钮事件——清空或取消
    /// 	<remark>2010-10-23 河北大学信管团队-项玥  </remark>
    /// </summary>
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        if (lblTitle.Text.Trim() == "添加公告")
        {
            txtTitle.Text = "";
            txtContent.Text = "";
        }
        else if (lblTitle.Text.Trim() == "编辑公告")
        {
            //转到新管理通知公告管理界面
            Response.Redirect("Notice_Manage.aspx");
        }
    }

}
